﻿using System;
using System.Collections.Generic; 
using System.Text;
using ATSIDAL;
using ATSModel;
using System.Data.SqlClient;
using System.Data;

namespace ATSDAL
{
    public class TRelevanceDal : BaseRepository_DT<TRelevanceInfo>, ITRelevance
    {
        #region
        private const string PARM_RELEVANCE_RETROSPECTSN = "@RetrospectSN";
        private const string PARM_RELEVANCE_ANTENNASN = "@ProductSN";
        private const string PARM_TPACKAGE_RELEVANCETIME = "@RelevanceTime";
        private const string PARM_TPACKAGE_RELEVANCEUSER = "@RelevanceUser";
        private const string PARM_TPACKAGE_PCIP = "@PCIP";
        private const string PARM_TPACKAGE_REMARK = "@Remark";
        private const string PARM_SN = "@SN";
        #endregion


        //检测条码是否关联
        public TRelevanceInfo IsRelevance(string SN)
        {
            SqlParameter parm = GetParameter(PARM_SN);
            parm.Value = SN;
            //parm[0].Value = retrospectSN;
            //parm[1].Value = antennaSN;
            return ExcuteSqlToGetEntity("sp_selRelevanceBySN", parm);
        } 


        public override TRelevanceInfo GetEntityRecord(SqlDataReader rdr)
        {
            TRelevanceInfo pac = new TRelevanceInfo
            {
                RetrospectSN = rdr.GetValue(0).ToString(),
                ProductSN = rdr.GetValue(1).ToString(), 
                RelevanceTime = Convert.ToDateTime(rdr.GetValue(2)),
                RelevanceUser = rdr.GetValue(3).ToString(),
                PCIP = rdr.GetValue(4).ToString(),
                Remark = rdr.GetValue(5).ToString()
            };
            return pac;
        }

        public override TRelevanceInfo GetEntityRecord()
        {
            TRelevanceInfo tr = new TRelevanceInfo();
            return tr;
        }

        public override string GetInsertsp()
        {
            return "sp_InsRelevanceInfo";
        }

        public override string GetUpdatesp()
        {
            return "sp_InsRelevanceInfo";
        }



        private static  SqlParameter GetParameter(string parm)
        {
            SqlParameter Parm = new SqlParameter(parm, SqlDbType.NVarChar, 50);
            return Parm;
        }

        private static SqlParameter[] GetRSNTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_RELEVANCE_RETROSPECTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_RELEVANCE_ANTENNASN, SqlDbType.NVarChar, 50)                
                };
            return parms;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_RELEVANCE_RETROSPECTSN,SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_RELEVANCE_ANTENNASN, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TPACKAGE_RELEVANCETIME,SqlDbType.DateTime),
                    new SqlParameter(PARM_TPACKAGE_RELEVANCEUSER,SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TPACKAGE_PCIP,SqlDbType.NVarChar, 20),
                    new SqlParameter(PARM_TPACKAGE_REMARK,SqlDbType.NVarChar, 50)

                };
            return parms;
        }

        public override void SetParameters(TRelevanceInfo relevance, params SqlParameter[] Parms)
        {
            Parms[0].Value = relevance.RetrospectSN;
            Parms[1].Value = relevance.ProductSN; 
            Parms[2].Value = relevance.RelevanceTime;
            Parms[3].Value = relevance.RelevanceUser;
            Parms[4].Value = relevance.PCIP;
            Parms[5].Value = relevance.Remark;
        }
 

        #region IBaseRepository<TRelevanceInfo> 成员


        TRelevanceInfo IBaseRepository<TRelevanceInfo>.LoadEntity<T1>(T1 Id)
        {
            throw new NotImplementedException();
        }

        public IList<TRelevanceInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("sp_selRelevance");
        }

        #endregion
    }
}
